package com.ruoyi.web.controller.system.api.cc;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.CallRecord;
import com.ruoyi.system.api.domain.Order;
import com.ruoyi.system.api.domain.User;
import com.ruoyi.system.api.service.OnlineServiceService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * @ClassName SparePartsController
 * @Description: 在线服务模块controller
 * @Author wlf
 * @Date 2020/3/2
 * @Version V1.0
 **/
@Api(tags = "在线服务")
@Controller
@RequestMapping("/api/cc/onlineService")
public class OnlineServiceController extends BaseController {

    @Autowired
    private OnlineServiceService onlineServiceService;

    private static final Logger log = LoggerFactory.getLogger(OnlineServiceController.class);

    /**
     * 建单申请
     * @methodName: createOrder
     * @description: TODO
     * @param params
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: wlf
     * @date: 2020/3/2 11:09
     **/
    @Log(title = "建单申请", businessType = BusinessType.INSERT)
    @PostMapping(value = "/createOrder", produces = "application/json")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "建单申请", httpMethod = "POST", notes = "建单申请")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师ID",name="enginner_id",required = true,dataType="String",example="工程师ID"),
            @ApiImplicitParam(value = "服务类型",name="service_type",required = true,dataType="String",example="服务类型"),
            @ApiImplicitParam(value = "服务子类型",name="Service_sub_type",required = true,dataType="String",example="服务子类型"),
            @ApiImplicitParam(value = "是否补单",name="IsRenew",required = true,dataType="String",example="是否补单"),
            @ApiImplicitParam(value = "是否VIP",name="IsVip",required = true,dataType="String",example="是否VIP"),
            @ApiImplicitParam(value = "联系人",name="Contactor",required = true,dataType="String",example="联系人"),
            @ApiImplicitParam(value = "手机号",name="mobile",required = true,dataType="String",example="手机号"),
            @ApiImplicitParam(value = "电话",name="tel",required = true,dataType="String",example="电话"),
            @ApiImplicitParam(value = "客户名称",name="CustName",required = true,dataType="String",example="客户名称"),
            @ApiImplicitParam(value = "联系地址",name="Adderss",required = true,dataType="String",example="联系地址"),
            @ApiImplicitParam(value = "设备型号",name="model",required = true,dataType="String",example="设备型号"),
            @ApiImplicitParam(value = "序列号",name="serialno",required = true,dataType="String",example="序列号"),
            @ApiImplicitParam(value = "物料号",name="Material",required = true,dataType="String",example="物料号"),
            @ApiImplicitParam(value = "期望时间",name="ExpectDate",required = true,dataType="String",example="期望时间"),
            @ApiImplicitParam(value = "保修性质",name="WarrantyType",required = true,dataType="String",example="保修性质"),
            @ApiImplicitParam(value = "保修开始",name="WarrantyStart",required = true,dataType="String",example="保修开始"),
            @ApiImplicitParam(value = "保修结束",name="WarrantyEnd",required = true,dataType="String",example="保修结束"),
            @ApiImplicitParam(value = "客户编号",name="CustID",required = true,dataType="String",example="客户编号"),
            @ApiImplicitParam(value = "仪器编号",name="Instrument_ID",required = true,dataType="String",example="仪器编号"),
            @ApiImplicitParam(value = "联系人编号",name="ContID",required = true,dataType="String",example="联系人编号"),
            @ApiImplicitParam(value = "故障描述",name="Remarks",required = true,dataType="String",example="故障描述")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    @JsonProperty("")
    public ResponseWithData<?> createOrder(@ApiParam(name="params", value="建单申请",required=true) @RequestBody String params){
        try {
//            System.out.println(params);
            Order order = new Order();
            if (StringUtils.isNotEmpty(params)) {
                order = JSONObject.parseObject(params, Order.class);
            }
            return onlineServiceService.createOrder(order);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
    /**
     * 电话解决记录
     * @methodName: submitCallRecordInfo
     * @description: TODO
     * @param params
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: wlf
     * @date: 2020/3/2 11:09
     **/
    @Log(title = "电话解决记录", businessType = BusinessType.INSERT)
    @PostMapping(value = "/submitCallRecordInfo", produces = "application/json")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "电话解决记录", httpMethod = "POST", notes = "电话解决记录")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "工程师ID",name="enginner_id",required = true,dataType="String",example="工程师ID"),
            @ApiImplicitParam(value = "联系人",name="Cont",required = true,dataType="String",example="联系人"),
            @ApiImplicitParam(value = "手机",name="Mobile",required = true,dataType="String",example="手机"),
            @ApiImplicitParam(value = "客户名称",name="CustName",required = true,dataType="String",example="客户名称"),
            @ApiImplicitParam(value = "序列号",name="Serial",required = true,dataType="String",example="序列号"),
            @ApiImplicitParam(value = "设备型号",name="EqModel",required = true,dataType="String",example="设备型号"),
            @ApiImplicitParam(value = "问题分类",name="QueType",required = true,dataType="String",example="问题分类"),
            @ApiImplicitParam(value = "是否解决",name="IsSolved",required = true,dataType="String",example="是否解决"),
            @ApiImplicitParam(value = "时长",name="Hours",required = true,dataType="Double",example="时长"),
            @ApiImplicitParam(value = "备注",name="Remark",dataType="String",example="备注")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    @JsonProperty("")
    public ResponseWithData<?> submitCallRecordInfo(@ApiParam(name="params", value="电话解决记录",required=true) @RequestBody String params){
        try {
            CallRecord obj = new CallRecord();
            if (StringUtils.isNotEmpty(params)) {
                obj = JSONObject.parseObject(params, CallRecord.class);
            }
            return onlineServiceService.submitCallRecordInfo(obj);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    @GetMapping (value = "/getUserContInfo")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "手机号获取联系人客户信息接口", httpMethod = "GET", notes = "手机号获取联系人客户信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号", name = "mobile", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getUserContInfo(@RequestParam(value="mobile",required=true) String mobile){
        try {
            return onlineServiceService.getUserContInfo(mobile);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    @GetMapping (value = "/getUserEqInfoByCustName")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "客户名称获取客户仪器信息接口", httpMethod = "GET", notes = "客户名称获取客户仪器信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "客户名称", name = "custName", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getUserEqInfoByCustName(@RequestParam(value="custName",required=true) String custName){
        try {
            return onlineServiceService.getUserEqInfoByCustName(custName);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    @GetMapping (value = "/getUserEqInfoBySerial")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "序列号获取客户仪器信息接口", httpMethod = "GET", notes = "序列号获取客户仪器信息接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "序列号", name = "serial", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getUserEqInfoBySerial(@RequestParam(value="serial",required=true) String serial){
        try {
            return onlineServiceService.getUserEqInfoBySerial(serial);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
}
